Ext.require(['AM.service.Support', 'AM.data.InitConfig']);


Ext.define("AM.component.Audio", {

    extend:'Ext.Component',
    autoEl:'audio',
    xtype: 'xbxAudio',


    constructor: function(config, xbxConfig) {
        var me = this;
        me.callParent(arguments);
        me.initConfig(config);
        me.addListener('render', function(){
            if (!Ext.isEmpty(config)) {
                var file = config.file;
                if (!Ext.isEmpty(file)) {
                    var reader = new FileReader();
                    reader.onload = function(re) {
                        me.el.dom.src = re.target.result;
                    }
                    reader.readAsDataURL(file);
                }
                var src = config.src;
                if (!Ext.isEmpty(src)) {
                    src = decodeURI(src);
                    me.el.dom.src = src;
                }
            }
            me.el.dom.controls = 'controls';

            if (!Ext.isEmpty(xbxConfig)) {
                AM.data.InitConfig.audio(me, xbxConfig);
            }

            var sp = AM.service.Support;
            sp.drag(me);
            sp.contextmenu(me)

            sp.animShow(me);
        })
    },

    style:{
        position: 'absolute'
    },

    src: null,

    config: {
        file:null,
        audioName: null
    }
});